<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
/*
	小程序粉丝管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$return['isread']=array('0'=>'未读','1'=>'已读');
if($_RQ['op']=='list'){
	//搜索
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if($_RQ['name']){
		$params['name like']='%'.trim($_RQ['name']).'%';
		$return['params']['name']=$_RQ['name'];
	}
	$fields=array('id','openid','logo','name');
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	$total='';
	$orderby='id desc';
	$list=pdo_getslice('jy_kefu_member',$params,array($pindex,$psize),$total,$fields,'',$orderby);
	$return['list']=$list?$list:array();
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			'0'=>array('op'=>'list','title'=>'用户信息'),
		),
		'list'=>array('data'=>'list','delall'=>false,'del_one'=>false,'edit'=>false,'list'=>array(
				array('name'=>'logo','title'=>'客户','type'=>'image'),
				array('name'=>'name','title'=>'昵称','type'=>'string'),
				array('name'=>'openid','title'=>'Openid/UID','type'=>'string'),
				array('name'=>'isblack','title'=>'黑名单','type'=>'switch','set'=>'set'),
				//array('name'=>'lasttime','title'=>'最后会话时间','type'=>'string'),
			),'action'=>array(
			array('type'=>'modal','op'=>'biaoqian','title'=>'标签'),
			//array('type'=>'href','op'=>'up','title'=>'同步会员'),
			array('type'=>'href','op'=>'chats','title'=>'会话管理'),
		)
		),
		'search_one'=>array('name'=>'name','add'=>false)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='chats'){
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_kefu_member',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
	}else{
		exi('请先选择用户','error');
	}
	$list=pdo_getall('jy_kefu_member_chat',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$id),array('id','chatid','getmid','lastmsg','msgtype'));
	if($list){
		foreach($list as &$row){
			$chat=pdo_getall('jy_kefu_chatlog',array('uniacid'=>$_SESSION['uniacid'],'chatid'=>$row['chatid']),array('id','chatid','getmid'));
			$getmember = pdo_get('jy_kefu_member',array('uniacid'=>$_SESSION['uniacid'],'id'=>$row['getmid']));
			$row['getlogo'] = $getmember['logo'];
			$row['getname'] = $getmember['name'];
			$row['createtime']=date('20y/m/d H:i:s',$row['createtime']);
		}
	}
	$return['list']=$list?$list:array();
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			'0'=>array('op'=>'list','title'=>'会话信息'),
		),
		'list'=>array('data'=>'list','delall'=>false,'del_one'=>false,'edit'=>false,'list'=>array(
				array('name'=>'getlogo','title'=>'对方logo','type'=>'image'),
				array('name'=>'getname','title'=>'对方昵称','type'=>'string'),
				array('name'=>'getmid','title'=>'Openid/UID','type'=>'string'),
				array('name'=>'isblack','title'=>'黑名单','type'=>'switch','set'=>'set'),
				array('name'=>'createtime','title'=>'会话时间','type'=>'string'),
			)
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='biaoqian'){
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_kefu_member',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
	}else{
		$item=array();
	}
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'desc'=>'备注详情',
		'edit'=>array(
			array('type'=>'string','title'=>'标签','name'=>'biaoqian', 'help'=>'' ),
			array('type'=>'string','title'=>'姓名','name'=>'realname', 'help'=>'' ),
			array('type'=>'string','title'=>'电话','name'=>'phone', 'help'=>'' ),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='set'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择客户！','error');
	}
	$postdata=get_postdata();
	$isblack=intval($postdata['isblack']);
	pdo_update('jy_kefu_member',array('isblack'=>$isblack),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	exi('操作成功！');
}
if($_RQ['op']=='up'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择客户！','error');
	}
	$member=pdo_get('core_members',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']),array('avatar','nickname'));
	$data=array(
		'logo'=>$member['avatar'],
		'name'=>$member['nickname'],
		'openid'=>$id,
	);
	pdo_update('jy_kefu_member',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	exi('操作成功！');
}
?>